package com.cssw.fyzb.busi.api.acct;

/**
 * @Author zhouxu
 * @create 2020-12-21 15:55
 */

import com.cssw.fyzb.busi.convert.Converter;
import com.cssw.fyzb.core.model.vo.acct.RnbBuyFCoinVo;
import com.cssw.fyzb.busi.service.acct.AcctService;
import com.cssw.fyzb.core.model.dodb.RnbExchangeFDef;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.ListProperty;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Property;
import com.ydn.appserver.annotations.Result;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author zhouxu
 * @create 2020-12-18 20:57
 */
@Function(description = "购买福币页面查询", parameters = {
        @Parameter(name = "userId", type = Type.String, description = "用户ID", required = true),
}, result = @Result(
        listProperties = {
                @ListProperty(name = "list", properties = {
                        @Property(name = "fCoin", type = Type.Decimal, description = "福币"),
                        @Property(name = "rnb", type = Type.Decimal, description = "人民币"),
                        @Property(name = "rfId", type = Type.Integer, description = "固定金额ID"),
                })
        }
))
@Component
public class BuyFCoinView implements Action {

    private static final Logger logger = LoggerFactory.getLogger(BuyFCoinView.class);

    @Autowired
    private AcctService acctService;

    @Override
    public Response execute(Request request) throws Exception {

        List<RnbExchangeFDef> list = acctService.queryRnbBuyFDef();
        List<RnbBuyFCoinVo> voList = ((Converter<List<RnbExchangeFDef>, List<RnbBuyFCoinVo>>) tmpList -> {
            List<RnbBuyFCoinVo> vos = new ArrayList<>();
            tmpList.forEach((v) -> {
                RnbBuyFCoinVo vo = new RnbBuyFCoinVo();
                vo.setFuCoin(v.getFCoin().setScale(2));
                vo.setRnb(v.getRnb().setScale(2));
                vo.setRfId(v.getRfId());
                vos.add(vo);
            });
            return vos;
        }).convert(list);

        return Response.success().put("list", voList);
    }
}
